<template>
  <div class="tenant-order-container">
    <!-- 搜索区域 -->
    <ContentWrap class="search-wrapper">
      <div class="search-header">
        <div class="header-icon">
          <Icon icon="ep:search" />
        </div>
        <div class="header-content">
          <h4 class="search-title">租户订单管理</h4>
          <p class="search-subtitle">查询和管理租户订单信息</p>
        </div>
      </div>

      <div class="search-form-container">
        <el-form
          :model="queryParams"
          ref="queryFormRef"
          :inline="true"
          label-width="100px"
          label-position="left"
          class="enhanced-search-form"
        >
          <div class="form-row">
            <el-form-item label="订单号" prop="orderNo" class="form-item">
              <el-input
                v-model="queryParams.orderNo"
                placeholder="请输入订单号"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:document" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="支付状态" prop="payStatus" class="form-item">
              <el-select
                v-model="queryParams.payStatus"
                placeholder="请选择支付状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:credit-card" />
                </template>
                <el-option label="已支付" value="10">
                  <div class="option-item">
                    <Icon icon="ep:check" class="option-icon success" />
                    <span>已支付</span>
                  </div>
                </el-option>
                <el-option label="未支付" value="0">
                  <div class="option-item">
                    <Icon icon="ep:close" class="option-icon danger" />
                    <span>未支付</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="发货状态" prop="deliveryStatus" class="form-item">
              <el-select
                v-model="queryParams.deliveryStatus"
                placeholder="请选择发货状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:van" />
                </template>
                <el-option label="未发货" value="0">
                  <div class="option-item">
                    <Icon icon="ep:close" class="option-icon danger" />
                    <span>未发货</span>
                  </div>
                </el-option>
                <el-option label="已发货" value="1">
                  <div class="option-item">
                    <Icon icon="ep:check" class="option-icon success" />
                    <span>已发货</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="物流单号" prop="deliveryNo" class="form-item">
              <el-input
                v-model="queryParams.deliveryNo"
                placeholder="请输入物流单号"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:box" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="支付时间" prop="payTime" class="form-item date-item">
              <el-date-picker
                v-model="queryParams.payTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
                class="enhanced-date-picker"
              >
                <template #prefix>
                  <Icon icon="ep:calendar" />
                </template>
              </el-date-picker>
            </el-form-item>

            <el-form-item label="创建时间" prop="createTime" class="form-item date-item">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
                class="enhanced-date-picker"
              >
                <template #prefix>
                  <Icon icon="ep:calendar" />
                </template>
              </el-date-picker>
            </el-form-item>
          </div>
        </el-form>

        <div class="form-actions">
          <el-button @click="handleQuery" type="primary" class="action-btn search-btn">
            <Icon icon="ep:search" class="btn-icon" />
            搜索
          </el-button>
          <el-button @click="resetQuery" class="action-btn reset-btn">
            <Icon icon="ep:refresh" class="btn-icon" />
            重置
          </el-button>
          <el-button
            type="primary"
            plain
            @click="openForm('create')"
            v-hasPermi="['system:tenant-order:create']"
            style="border-radius: 6px"
          >
            <Icon icon="ep:plus" class="btn-icon" />
            新增
          </el-button>
          <el-button
            type="success"
            plain
            @click="handleExport"
            :loading="exportLoading"
            v-hasPermi="['system:tenant-order:export']"
            class="action-btn export-btn"
          >
            <Icon icon="ep:download" class="btn-icon" />
            导出
          </el-button>
        </div>
      </div>
    </ContentWrap>

    <!-- 列表区域 -->
    <ContentWrap class="table-wrapper">
      <div class="table-header">
        <div class="header-icon">
          <Icon icon="ep:list" />
        </div>
        <div class="header-content">
          <h4 class="table-title">订单列表</h4>
          <p class="table-subtitle">共 {{ total }} 个订单</p>
        </div>
      </div>

      <div class="table-container">
        <el-table
          v-loading="loading"
          :data="list"
          :stripe="true"
          :show-overflow-tooltip="true"
          class="enhanced-table"
          :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
        >
          <el-table-column
            label="租户名称"
            align="center"
            prop="tenantName"
            width="120px"
            fixed="left"
          >
            <template #default="scope">
              <div class="tenant-cell">
                <Icon icon="ep:office-building" class="cell-icon" />
                <span class="cell-text">{{ scope.row.tenantName }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="充值订单号"
            align="center"
            prop="orderNo"
            width="200px"
            fixed="left"
          >
            <template #default="scope">
              <div class="order-no-cell">
                <Icon icon="ep:document" class="cell-icon" />
                <span class="cell-text">{{ scope.row.orderNo }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="订单类型"
            align="center"
            prop="orderType"
            width="150px"
            fixed="left"
          >
            <template #default="scope">
              <div class="type-cell">
                <el-tag class="enhanced-tag type-tag">
                  <Icon icon="ep:box" class="tag-icon" />
                  {{ orderTypeMap[scope.row.orderType] }}
                </el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="产品名称"
            align="center"
            prop="subject"
            width="150px"
            fixed="left"
          >
            <template #default="scope">
              <div class="subject-cell">
                <Icon icon="ep:goods" class="cell-icon" />
                <span class="cell-text">{{ scope.row.subject }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="支付状态"
            align="center"
            prop="payStatus"
            width="150px"
            fixed="left"
          >
            <template #default="scope">
              <div class="status-cell">
                <el-tag
                  v-if="scope.row.payStatus == 10"
                  type="success"
                  effect="dark"
                  class="enhanced-tag"
                >
                  <Icon icon="ep:check" class="tag-icon" />
                  已支付
                </el-tag>
                <el-tag v-else type="danger" class="enhanced-tag">
                  <Icon icon="ep:close" class="tag-icon" />
                  未支付
                </el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="发货状态" align="center" prop="deliveryStatus" width="150px">
            <template #default="scope">
              <div class="status-cell">
                <el-tag v-if="scope.row.deliveryStatus == 1" class="enhanced-tag">
                  <Icon icon="ep:check" class="tag-icon" />
                  已发货
                </el-tag>
                <el-tag v-else type="danger" class="enhanced-tag">
                  <Icon icon="ep:close" class="tag-icon" />
                  未发货
                </el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="购买数量" align="center" prop="num" width="150px">
            <template #default="scope">
              <div class="number-cell">
                <Icon icon="ep:pie-chart" class="cell-icon" />
                <span class="cell-text">{{ scope.row.num }}</span>
                <span class="unit">件</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="订单金额" align="center" prop="totalPrice" width="150px">
            <template #default="scope">
              <div class="price-cell">
                <Icon icon="ep:coin" class="cell-icon" />
                <span class="price-text">{{ scope.row.totalPrice }}</span>
                <span class="unit">元</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="优惠金额" align="center" prop="couponPrice" width="150px">
            <template #default="scope">
              <div class="price-cell discount">
                <Icon icon="ep:discount" class="cell-icon" />
                <span class="price-text">{{ scope.row.couponPrice }}</span>
                <span class="unit">元</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="支付金额" align="center" prop="payPrice" width="150px">
            <template #default="scope">
              <div class="price-cell pay">
                <Icon icon="ep:wallet" class="cell-icon" />
                <span class="price-text">{{ scope.row.payPrice }}</span>
                <span class="unit">元</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="发货方式" align="center" prop="deliveryType" width="150px">
            <template #default="scope">
              <div class="delivery-cell">
                <el-tag class="enhanced-tag delivery-tag">
                  <Icon
                    :icon="scope.row.deliveryType == 1 ? 'ep:monitor' : 'ep:van'"
                    class="tag-icon"
                  />
                  {{ scope.row.deliveryType == 1 ? '虚拟发货' : '物流发货' }}
                </el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="物流名称" align="center" prop="deliveryName" width="150px">
            <template #default="scope">
              <div class="delivery-name-cell">
                <Icon icon="ep:van" class="cell-icon" />
                <span class="cell-text">{{ scope.row.deliveryName || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="物流单号" align="center" prop="deliveryNo" width="150px">
            <template #default="scope">
              <div class="delivery-no-cell">
                <Icon icon="ep:box" class="cell-icon" />
                <span class="cell-text">{{ scope.row.deliveryNo || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="支付时间"
            align="center"
            prop="payTime"
            :formatter="dateFormatter"
            width="180px"
          >
            <template #default="scope">
              <div class="time-cell">
                <Icon icon="ep:clock" class="cell-icon" />
                <span class="cell-text">{{
                  dateFormatter(scope.row, null, scope.row.payTime)
                }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            :formatter="dateFormatter"
            width="180px"
          >
            <template #default="scope">
              <div class="time-cell">
                <Icon icon="ep:calendar" class="cell-icon" />
                <span class="cell-text">{{
                  dateFormatter(scope.row, null, scope.row.createTime)
                }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" fixed="right" width="250px">
            <template #default="scope">
              <div class="action-cell">
                <el-button
                  link
                  type="primary"
                  @click="openForm('update', scope.row.id)"
                  v-hasPermi="['system:tenant-order:update']"
                  :disabled="scope.row.deliveryType != 2 && scope.row.deliveryStatus != 0"
                  class="action-button delivery-btn"
                >
                  <Icon icon="ep:van" class="btn-icon" />
                  订单发货
                </el-button>
                <el-button
                  link
                  type="primary"
                  :disabled="scope.row.deliveryType != 2"
                  @click="seeReceivInformation(scope.row.id)"
                  class="action-button info-btn"
                >
                  <Icon icon="ep:user" class="btn-icon" />
                  收货人信息
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </ContentWrap>

    <!-- 表单弹窗：添加/修改 -->
    <TenantOrderForm ref="formRef" @success="getList" />

    <!-- 收货信息弹窗 -->
    <Dialog title="收货信息" v-model="dialog" width="500px" class="receiver-dialog">
      <div class="receiver-header">
        <div class="header-icon">
          <Icon icon="ep:user" />
        </div>
        <div class="header-content">
          <h4 class="dialog-title">收货人信息</h4>
          <p class="dialog-subtitle">查看订单收货详情</p>
        </div>
      </div>

      <ContentWrap class="receiver-content">
        <el-descriptions column="1" class="enhanced-descriptions">
          <el-descriptions-item label="发货方式">
            <div class="desc-item">
              <Icon icon="ep:van" class="desc-icon" />
              <span>物流</span>
            </div>
          </el-descriptions-item>

          <el-descriptions-item label="收件人" label-class-name="labelWidth">
            <div class="desc-item">
              <Icon icon="ep:user" class="desc-icon" />
              <span>{{ orderInfo.receiver }}</span>
            </div>
          </el-descriptions-item>

          <el-descriptions-item label="联系方式">
            <div class="desc-item">
              <Icon icon="ep:phone" class="desc-icon" />
              <span>{{ orderInfo.mobile }}</span>
            </div>
          </el-descriptions-item>

          <el-descriptions-item label="所在地" label-class-name="labelWidth">
            <div class="desc-item area-item">
              <Icon icon="ep:location" class="desc-icon" />
              <el-cascader
                v-model="orderInfo.areaId"
                :options="areaList"
                :props="defaultProps"
                class="enhanced-cascader"
                clearable
                disabled
                filterable
                placeholder="请选择收货地址"
              />
            </div>
          </el-descriptions-item>

          <el-descriptions-item label="详细地址">
            <div class="desc-item">
              <Icon icon="ep:map-location" class="desc-icon" />
              <span>{{ orderInfo.detailAddress }}</span>
            </div>
          </el-descriptions-item>
        </el-descriptions>
      </ContentWrap>
    </Dialog>
  </div>
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as TenantOrderApi from '@/api/system/tenantOrder'
import { defaultProps } from '@/utils/tree'
import TenantOrderForm from './TenantOrderForm.vue'
import * as AreaApi from '@/api/system/area'

defineOptions({ name: 'TenantOrder' })

const message = useMessage() // 消息弹窗

const orderTypeMap = {
  1: '余额充值',
  2: '购买套餐',
  3: '套餐续费'
}

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const dialog = ref(false)
const orderInfo = ref('')
const areaList = ref([])
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderNo: null,
  payStatus: null,
  deliveryStatus: null,
  deliveryNo: null,
  payTime: [],
  createTime: []
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/*查询收货地址*/
const seeReceivInformation = async (id) => {
  orderInfo.value = await TenantOrderApi.getReceiverBySystem(id)
  dialog.value = true
}
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await TenantOrderApi.getTenantOrderPageBySystem(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await TenantOrderApi.exportTenantOrder(queryParams)
    download.excel(data, '租户订单.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}
const getAreaList = async () => {
  areaList.value = await AreaApi.getAreaTree()
}
/** 初始化 **/
onMounted(() => {
  getList()
  getAreaList()
})
</script>

<style lang="scss" scoped>
// 主题色变量
$primary-color: #0052cc;
$primary-light: rgba(0, 82, 204, 0.1);
$primary-border: rgba(0, 82, 204, 0.3);
$success-color: #67c23a;
$warning-color: #e6a23c;
$danger-color: #f56c6c;
$info-color: #909399;
$text-primary: #303133;
$text-regular: #606266;
$text-secondary: #909399;
$text-placeholder: #c0c4cc;
$border-color: #dcdfe6;
$border-light: #e4e7ed;
$bg-color: #f5f7fa;
$shadow-light: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
$shadow-base:
  0 2px 4px rgba(0, 0, 0, 0.12),
  0 0 6px rgba(0, 0, 0, 0.04);
$border-radius: 12px;
$border-radius-small: 8px;

.tenant-order-container {
  padding: 0;
  background: $bg-color;
  min-height: 100vh;

  @media (max-width: 768px) {
    padding: 0;
  }
}

/* 搜索区域样式 */
.search-wrapper {
  margin-bottom: 16px;
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.search-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;

  @media (max-width: 768px) {
    padding: 16px 20px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

.header-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: $border-radius-small;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;

  @media (max-width: 768px) {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

.header-content {
  flex: 1;
  margin-left: 12px;

  @media (max-width: 768px) {
    margin-left: 0;
  }
}

.search-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 16px;
  }
}

.search-subtitle {
  font-size: 13px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.search-form-container {
  padding: 24px;
  background: white;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-search-form {
  .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;

    @media (max-width: 768px) {
      flex-direction: column;
      gap: 12px;
      margin-bottom: 16px;
    }
  }

  .form-item {
    flex: 1;
    min-width: 260px;
    margin-bottom: 0;

    @media (max-width: 768px) {
      min-width: auto;
      flex: none;
    }

    &.date-item {
      min-width: 300px;

      @media (max-width: 768px) {
        min-width: auto;
      }
    }

    :deep(.el-form-item__label) {
      font-weight: 600;
      color: $text-regular;
      padding-bottom: 8px;

      @media (max-width: 768px) {
        font-size: 14px;
        width: 100% !important;
        text-align: left !important;
        margin-bottom: 8px;
      }
    }

    :deep(.el-form-item__content) {
      @media (max-width: 768px) {
        margin-left: 0 !important;
      }
    }
  }

  // H5适配：表单项垂直布局
  @media (max-width: 768px) {
    :deep(.el-form-item) {
      display: block;
    }
  }
}

/* 输入框样式 */
.enhanced-input {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 12px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }
}

/* 选择器样式 */
.enhanced-select {
  width: 100%;

  :deep(.el-select__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 8px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focused {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }
}

/* 日期选择器样式 */
.enhanced-date-picker {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 12px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }
}

/* 选项样式 */
.option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.option-icon {
  font-size: 14px;

  &.success {
    color: $success-color;
  }

  &.danger {
    color: $danger-color;
  }
}

/* 操作按钮区域 */
.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 8px;
  }
}

.action-btn {
  border-radius: $border-radius-small;
  padding: 10px 16px;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;

  &:hover {
    transform: translateY(-1px);
  }

  @media (max-width: 768px) {
    width: 100%;
    justify-content: center;
    padding: 12px 16px;
  }

  .btn-icon {
    font-size: 14px;
  }

  &.search-btn {
    background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
    border: none;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
    }
  }

  &.reset-btn {
    border: 2px solid $border-color;
    color: $text-regular;

    &:hover {
      border-color: $primary-color;
      color: $primary-color;
      background: $primary-light;
    }
  }

  &.add-btn {
    border: 2px solid $primary-color;
    color: $primary-color;

    &:hover {
      background: $primary-color;
      color: white;
    }
  }

  &.export-btn {
    border: 2px solid $success-color;
    color: $success-color;

    &:hover {
      background: $success-color;
      color: white;
    }
  }
}

/* 表格区域样式 */
.table-wrapper {
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.table-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;

  @media (max-width: 768px) {
    padding: 16px 20px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

.table-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 16px;
  }
}

.table-subtitle {
  font-size: 13px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.table-container {
  background: white;
  overflow-x: auto;
}

.enhanced-table {
  :deep(.el-table__header) {
    th {
      background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%) !important;
      color: $text-primary !important;
      font-weight: 600 !important;
      border-bottom: 2px solid $primary-light;
      padding: 16px 12px;
    }
  }

  :deep(.el-table__body) {
    tr {
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light !important;
      }

      td {
        padding: 14px 12px;
        border-bottom: 1px solid $border-light;
      }
    }

    .el-table__row--striped {
      background: #fafbff;

      &:hover {
        background: $primary-light !important;
      }
    }
  }

  // H5适配
  @media (max-width: 768px) {
    :deep(.el-table__header) th {
      padding: 12px 8px;
      font-size: 13px;
    }

    :deep(.el-table__body) td {
      padding: 12px 8px;
      font-size: 12px;
    }
  }
}

/* 表格单元格样式 */
.tenant-cell,
.order-no-cell,
.subject-cell,
.delivery-name-cell,
.delivery-no-cell,
.time-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.type-cell,
.status-cell,
.delivery-cell {
  display: flex;
  justify-content: center;
}

.number-cell,
.price-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;

  &.discount {
    .cell-icon {
      color: $warning-color;
    }
    .price-text {
      color: $warning-color;
    }
  }

  &.pay {
    .cell-icon {
      color: $success-color;
    }
    .price-text {
      color: $success-color;
      font-weight: 600;
    }
  }
}

.cell-icon {
  font-size: 14px;
  flex-shrink: 0;
  color: $primary-color;
}

.cell-text {
  color: $text-regular;
  font-weight: 500;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.price-text {
  color: $primary-color;
  font-weight: 600;
  font-size: 16px;

  @media (max-width: 768px) {
    font-size: 14px;
  }
}

.unit {
  font-size: 11px;
  color: $text-secondary;
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 4px;
  border-radius: 3px;

  @media (max-width: 768px) {
    font-size: 10px;
  }
}

/* 标签样式 */
.enhanced-tag {
  border-radius: 6px;
  font-weight: 500;
  padding: 4px 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;

  @media (max-width: 768px) {
    font-size: 11px;
    padding: 3px 6px;
  }

  &.type-tag {
    background: linear-gradient(135deg, $primary-light 0%, rgba(0, 82, 204, 0.05) 100%);
    color: $primary-color;
    border: 1px solid $primary-border;
  }

  &.delivery-tag {
    background: linear-gradient(135deg, rgba(103, 194, 58, 0.1) 0%, rgba(103, 194, 58, 0.05) 100%);
    color: $success-color;
    border: 1px solid rgba(103, 194, 58, 0.3);
  }
}

.tag-icon {
  font-size: 12px;
}

/* 操作按钮 */
.action-cell {
  display: flex;
  justify-content: center;
  gap: 8px;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 4px;
  }
}

.action-button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    transform: scale(1.05);
  }

  .btn-icon {
    font-size: 12px;
  }

  @media (max-width: 768px) {
    padding: 4px 8px;
    font-size: 11px;
    width: 100%;
    justify-content: center;
  }

  &.delivery-btn:hover {
    background: rgba(0, 82, 204, 0.1);
    color: $primary-color;
  }

  &.info-btn:hover {
    background: rgba(103, 194, 58, 0.1);
    color: $success-color;
  }
}

/* 分页样式 */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px 24px;
  background: white;
  border-top: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px 20px;
  }

  :deep(.el-pagination) {
    .el-pager li {
      border-radius: 6px;
      margin: 0 2px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }

      &.is-active {
        background: $primary-color;
        color: white;
      }
    }

    .btn-prev,
    .btn-next {
      border-radius: 6px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }
    }

    @media (max-width: 768px) {
      .el-pagination__sizes,
      .el-pagination__jump {
        display: none;
      }
    }
  }
}

/* 收货信息弹窗 */
.receiver-dialog {
  :deep(.el-dialog) {
    border-radius: $border-radius;
    overflow: hidden;

    @media (max-width: 768px) {
      width: 95% !important;
      margin: 0 auto;
    }
  }

  :deep(.el-dialog__header) {
    padding: 0;
    border-bottom: none;
  }

  :deep(.el-dialog__body) {
    padding: 0;
  }
}

.receiver-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;

  @media (max-width: 768px) {
    padding: 16px 20px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

.dialog-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 16px;
  }
}

.dialog-subtitle {
  font-size: 13px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.receiver-content {
  padding: 24px;
  background: white;

  @media (max-width: 768px) {
    padding: 16px;
  }

  :deep(.el-card__body) {
    padding: 0;
  }
}

.enhanced-descriptions {
  :deep(.el-descriptions__label) {
    font-weight: 600;
    color: $text-regular;
    width: 100px;

    @media (max-width: 768px) {
      font-size: 14px;
      width: 80px;
    }
  }

  :deep(.el-descriptions__content) {
    color: $text-primary;
  }

  :deep(.el-descriptions-item) {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid $border-light;

    &:last-child {
      border-bottom: none;
      margin-bottom: 0;
      padding-bottom: 0;
    }

    @media (max-width: 768px) {
      margin-bottom: 12px;
      padding-bottom: 12px;
    }
  }
}

.desc-item {
  display: flex;
  align-items: center;
  gap: 8px;

  &.area-item {
    align-items: flex-start;
  }
}

.desc-icon {
  color: $primary-color;
  font-size: 16px;
  flex-shrink: 0;

  @media (max-width: 768px) {
    font-size: 14px;
  }
}

.enhanced-cascader {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .tenant-order-container {
    background: #1f2937;
  }

  .search-wrapper,
  .table-wrapper {
    background: #374151;
    border-color: #4b5563;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .search-form-container,
  .table-container,
  .pagination-wrapper,
  .receiver-content {
    background: #374151;
  }

  .search-title,
  .table-title,
  .dialog-title {
    color: #f9fafb;
  }

  .cell-text {
    color: #f9fafb;
  }

  .enhanced-table {
    :deep(.el-table__header) {
      th {
        background: #4b5563 !important;
        color: #f9fafb !important;
        border-bottom-color: #6b7280;
      }
    }

    :deep(.el-table__cell) {
      border-bottom-color: #4b5563;
    }
  }

  .enhanced-input,
  .enhanced-select,
  .enhanced-date-picker {
    :deep(.el-input__wrapper),
    :deep(.el-select__wrapper) {
      background: #4b5563;
      border-color: #6b7280;

      .el-input__inner {
        color: #f9fafb;
      }
    }
  }

  .option-icon {
    &.success {
      color: #34d399;
    }

    &.danger {
      color: #f87171;
    }
  }

  .unit {
    background: rgba(255, 255, 255, 0.1);
    color: #9ca3af;
  }

  .enhanced-tag {
    &.type-tag {
      background: linear-gradient(
        135deg,
        rgba(96, 165, 250, 0.1) 0%,
        rgba(96, 165, 250, 0.05) 100%
      );
      color: #60a5fa;
      border-color: rgba(96, 165, 250, 0.3);
    }

    &.delivery-tag {
      background: linear-gradient(
        135deg,
        rgba(52, 211, 153, 0.1) 0%,
        rgba(52, 211, 153, 0.05) 100%
      );
      color: #34d399;
      border-color: rgba(52, 211, 153, 0.3);
    }
  }

  .enhanced-descriptions {
    :deep(.el-descriptions__label) {
      color: #d1d5db;
    }

    :deep(.el-descriptions__content) {
      color: #f9fafb;
    }

    :deep(.el-descriptions-item) {
      border-bottom-color: #4b5563;
    }
  }

  .desc-icon {
    color: #60a5fa;
  }

  .enhanced-cascader {
    :deep(.el-input__wrapper) {
      background: #4b5563;
      border-color: #6b7280;

      .el-input__inner {
        color: #f9fafb;
      }
    }
  }
}

/* 响应式优化 */
@media (max-width: 480px) {
  .search-header,
  .table-header,
  .receiver-header {
    padding: 12px 16px;
  }

  .search-form-container,
  .receiver-content {
    padding: 12px;
  }

  .pagination-wrapper {
    padding: 12px 16px;
  }

  .enhanced-table {
    :deep(.el-table__header) th {
      padding: 10px 6px;
      font-size: 12px;
    }

    :deep(.el-table__body) td {
      padding: 10px 6px;
      font-size: 11px;
    }
  }

  .cell-text {
    font-size: 11px;
  }

  .price-text {
    font-size: 13px;
  }

  .unit {
    font-size: 9px;
  }

  .action-button {
    padding: 3px 6px;
    font-size: 10px;
  }

  .enhanced-tag {
    font-size: 10px;
    padding: 2px 4px;
  }
}

// 原有样式保持
::v-deep(.labelWidth) {
  display: inline-block;
  width: 56px !important;
}
</style>
